package cn.snailteam.recruitment.dao.impl;

import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.LockMode;
import org.springframework.context.ApplicationContext;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import cn.snailteam.recruitment.dao.IWorkExperienceInfoListDAO;
import cn.snailteam.recruitment.entity.WorkExperienceInfoList;

/**
 * A data access object (DAO) providing persistence and search support for
 * WorkExperienceInfoList entities. Transaction control of the save(), update()
 * and delete() operations can directly support Spring container-managed
 * transactions or they can be augmented to handle user-managed Spring
 * transactions. Each of these methods provides additional information for how
 * to configure it for the desired type of transaction control.
 * 
 * @see cn.snailteam.recruitment.dao.impl.WorkExperienceInfoList
 * @author MyEclipse Persistence Tools
 */

public class WorkExperienceInfoListDAOImpl 
	extends HibernateDaoSupport implements IWorkExperienceInfoListDAO{
	private static final Log log = LogFactory
			.getLog(WorkExperienceInfoListDAOImpl.class);
	// property constants
	public static final String COMPANY_NAME = "companyName";
	public static final String NATURE_COMPANY = "natureCompany";
	public static final String COMPANY_SCALE = "companyScale";
	public static final String START_TIME = "startTime";
	public static final String END_TIME = "endTime";
	public static final String SALARY = "salary";
	public static final String DEPARTMENT = "department";
	public static final String JOB_SPECIFICATION = "jobSpecification";
	public static final String JOB_DESC = "jobDesc";

	protected void initDao() {
		// do nothing
	}

	public void save(WorkExperienceInfoList transientInstance) {
		log.debug("saving WorkExperienceInfoList instance");
		try {
			getHibernateTemplate().save(transientInstance);
			log.debug("save successful");
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}
	}

	public void delete(WorkExperienceInfoList persistentInstance) {
		log.debug("deleting WorkExperienceInfoList instance");
		try {
			getHibernateTemplate().delete(persistentInstance);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	public WorkExperienceInfoList findById(java.lang.Integer id) {
		log.debug("getting WorkExperienceInfoList instance with id: " + id);
		try {
			WorkExperienceInfoList instance = (WorkExperienceInfoList) getHibernateTemplate()
					.get(
							"cn.snailteam.recruitment.dao.impl.WorkExperienceInfoList",
							id);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	public List findByExample(WorkExperienceInfoList instance) {
		log.debug("finding WorkExperienceInfoList instance by example");
		try {
			List results = getHibernateTemplate().findByExample(instance);
			log.debug("find by example successful, result size: "
					+ results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}

	public List findByProperty(String propertyName, Object value) {
		log.debug("finding WorkExperienceInfoList instance with property: "
				+ propertyName + ", value: " + value);
		try {
			String queryString = "from WorkExperienceInfoList as model where model."
					+ propertyName + "= ?";
			return getHibernateTemplate().find(queryString, value);
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}

	public List findByCompanyName(Object companyName) {
		return findByProperty(COMPANY_NAME, companyName);
	}

	public List findByNatureCompany(Object natureCompany) {
		return findByProperty(NATURE_COMPANY, natureCompany);
	}

	public List findByCompanyScale(Object companyScale) {
		return findByProperty(COMPANY_SCALE, companyScale);
	}

	public List findByStartTime(Object startTime) {
		return findByProperty(START_TIME, startTime);
	}

	public List findByEndTime(Object endTime) {
		return findByProperty(END_TIME, endTime);
	}

	public List findBySalary(Object salary) {
		return findByProperty(SALARY, salary);
	}

	public List findByDepartment(Object department) {
		return findByProperty(DEPARTMENT, department);
	}

	public List findByJobSpecification(Object jobSpecification) {
		return findByProperty(JOB_SPECIFICATION, jobSpecification);
	}

	public List findByJobDesc(Object jobDesc) {
		return findByProperty(JOB_DESC, jobDesc);
	}

	public List findAll() {
		log.debug("finding all WorkExperienceInfoList instances");
		try {
			String queryString = "from WorkExperienceInfoList";
			return getHibernateTemplate().find(queryString);
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}

	public WorkExperienceInfoList merge(WorkExperienceInfoList detachedInstance) {
		log.debug("merging WorkExperienceInfoList instance");
		try {
			WorkExperienceInfoList result = (WorkExperienceInfoList) getHibernateTemplate()
					.merge(detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	public void attachDirty(WorkExperienceInfoList instance) {
		log.debug("attaching dirty WorkExperienceInfoList instance");
		try {
			getHibernateTemplate().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public void attachClean(WorkExperienceInfoList instance) {
		log.debug("attaching clean WorkExperienceInfoList instance");
		try {
			getHibernateTemplate().lock(instance, LockMode.NONE);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public static WorkExperienceInfoListDAOImpl getFromApplicationContext(
			ApplicationContext ctx) {
		return (WorkExperienceInfoListDAOImpl) ctx
				.getBean("WorkExperienceInfoListDAO");
	}
}